package symbol;

public class BasicSymbol extends Symbol {
    private final SymbolKind kind;
    // 在中间代码生成时，添加全局变常量的值
    private int valueNum;
    private boolean canCaclulate = false;

    public BasicSymbol(String name, SymbolType type, SymbolKind kind, int scopeLevel, int scopeNumber) {
        super(name, type, scopeLevel, scopeNumber);
        this.kind = kind;
    }

    public BasicSymbol(String name, SymbolType type, SymbolKind kind, int scopeLevel, int scopeNumber, int valueNum) {
        super(name, type, scopeLevel, scopeNumber);
        this.kind = kind;
        this.valueNum = valueNum;
        if (kind == SymbolKind.CONSTANT) {
            canCaclulate = true;
        }
    }

    public SymbolKind getKind() {
        return kind;
    }

    public int getValueNum() {
        return valueNum;
    }

    public boolean canCaclulate() {
        return canCaclulate;
    }

    public void setValue(int valueNum) {
        this.valueNum = valueNum;
        canCaclulate = true;
    }

    public String getTypeName() {
        if (kind == SymbolKind.CONSTANT && getType() == SymbolType.INT) {
            return "ConstInt";
        } else if (kind == SymbolKind.CONSTANT && getType() == SymbolType.CHAR) {
            return "ConstChar";
        } else if (kind == SymbolKind.VARIABLE && getType() == SymbolType.INT) {
            return "Int";
        } else if (kind == SymbolKind.VARIABLE && getType() == SymbolType.CHAR) {
            return "Char";
        } else {
            return "Unknown";
        }
    }
}
